package cn.kaguyaever.service.impl;

import cn.kaguyaever.dao.JudgeDao;
import cn.kaguyaever.dao.UserDao;
import cn.kaguyaever.dao.impl.JudgeDaoImpl;
import cn.kaguyaever.dao.impl.UserDaoImpl;
import cn.kaguyaever.entity.Judge;
import cn.kaguyaever.entity.User;
import cn.kaguyaever.service.UserService;

public class UserServiceImpl implements UserService {

    private UserDao userDao = new UserDaoImpl();

    private JudgeDao judgeDao = new JudgeDaoImpl();

    public void registerUser(User user) {
        userDao.saveUser(user);
    }

    public User login(User user) {
        return userDao.queryUserByUsernameAndPassword(user.getUsername(),user.getPassword());
    }

    public boolean existsUsername(String username) {
        if(userDao.queryUserByUsername(username)==null){
            //等于null说明用户名可用
            return false;
        }
        return true;
    }

    public void changePassword(String password,Integer id){
        userDao.changePassword(password,id);
    }
}
